package com.example.libraryapp.dialog.personal;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.example.libraryapp.R;
import com.example.libraryapp.dialog.DiyDialog;
import com.example.libraryapp.dialog.OnExitDialogListener;

/**
 * @author 伍凯铭
 * @since 2020/8/3
 */
public class FavourDialog implements View.OnClickListener{

    private DiyDialog dialog;

    private EditText mInputText;

    private OnPersonalListener mOnPersonalListener;

    public FavourDialog(Context context, OnPersonalListener onPersonalListener) {
        this.mOnPersonalListener = onPersonalListener;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_favour, null);
        dialog = new DiyDialog(context, view);
        mInputText = view.findViewById(R.id.input_favour);
        view.findViewById(R.id.cancel_btn).setOnClickListener(this);
        view.findViewById(R.id.commit_btn).setOnClickListener(this);
    }

    public String getText() {
        return mInputText.getText().toString();
    }

    public void setText(String name) {
        mInputText.setText(name);
    }


    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.commit_btn) {
            mOnPersonalListener.onFavourSure(getText());
        }
        dismiss();
    }

    public void dismiss(){
        dialog.closeDiyDialog();
    }

    public void show() {
        dialog.showDiyDialog();
    }
}
